import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hack_a_tone/bloc/jira_service.dart';
import 'package:introduction_screen/introduction_screen.dart';
import 'package:rounded_loading_button_plus/rounded_loading_button.dart';

class IntroScreen extends StatefulWidget {
  const IntroScreen({super.key});

  @override
  State<IntroScreen> createState() => _IntroScreenState();
}

class _IntroScreenState extends State<IntroScreen> {
  TextEditingController email = TextEditingController(),
      token = TextEditingController(),
      domain = TextEditingController();
  final RoundedLoadingButtonController _btnController =
      RoundedLoadingButtonController();
  @override
  Widget build(BuildContext context) {
    return IntroductionScreen(
      pages: [
        PageViewModel(
          title: "Добро пожаловать в YAPTAT!",
          body:
              "Сами вы его выбрали, или его выбрали за вас, это лучшее приложение из оставшихся!",
          image: const Center(
            child: Icon(Icons.waving_hand, size: 50.0),
          ),
        ),
        PageViewModel(
          title: "Нужно войти в Jira",
          bodyWidget: Column(
            children: [
              SizedBox(
                  width: 400,
                  child: Padding(
                    padding: const EdgeInsets.symmetric(vertical: 8),
                    child: TextField(
                        controller: email,
                        decoration: const InputDecoration(
                            border: OutlineInputBorder(), hintText: 'email')),
                  )),
              SizedBox(
                  width: 400,
                  child: Padding(
                    padding: const EdgeInsets.symmetric(vertical: 8),
                    child: TextField(
                        obscureText: true,
                        controller: token,
                        decoration: const InputDecoration(
                            border: OutlineInputBorder(), hintText: 'token')),
                  )),
              SizedBox(
                  width: 400,
                  child: Padding(
                    padding: const EdgeInsets.symmetric(vertical: 8),
                    child: TextField(
                        controller: domain,
                        decoration: const InputDecoration(
                            border: OutlineInputBorder(), hintText: 'domain')),
                  )),
              RoundedLoadingButton(
                controller: _btnController,
                onPressed: () async {
                  await BlocProvider.of<JiraCubit>(context).login(email.text, token.text, domain.text);
                  _btnController.success();
                },
                child:
                    const Text('Войти', style: TextStyle(color: Colors.white)),
              )
            ],
          ),
        )
      ],
      showSkipButton: false,
      showNextButton: true,
      freeze: true,
      next: const Text("Далее"),
      skip: const Text("Skip"),
      done: const Text("Начать"),
      onDone: () {
        // On button pressed
        Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false);
      },
    );
  }
}
